﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
using System.Data;

namespace BLLA
{
    public partial class View_Order_OperationFlowInfo : BaseBLL<Model.View_Order_OperationFlowInfo>, IBLL.IView_Order_OperationFlowInfoBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        IBLL.IBLLSession bl = DI.SpringHelper.GetObject<IBLL.IBLLSession>("BLLSession");

        /// <summary>
        /// 获取系统操作流水列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="Time_Start">（""-全部/yyyyMMdd）</param>
        /// <param name="Time_End">（""-全部/yyyyMMdd）</param>
        /// <param name="LogType">（""-全部/Basic_Dict_T.DictId=35）</param>
        /// <param name="Operat_Result">（""-全部/成功/失败/异常）</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">1:json;2:xml</param>
        /// <returns></returns>
        public string GetOrder_OperationFlow(int pageIndex, int pageSize, string Time_Start, string Time_End, string LogType, string Operat_Result, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                //string tj = "";
                var predicate = PredicateBuilder.True<Model.View_Order_OperationFlowInfo>();
                if (Time_Start != null && Time_Start != "")
                {
                    predicate = predicate.And(o => o.OperationTime.CompareTo(Time_Start) > 0);
                    //tj += " AND OperationTime >= '" + Time_Start + "'";
                }
                if (Time_End != null && Time_End != "")
                {
                    predicate = predicate.And(o => o.OperationTime.CompareTo(Time_End) < 0);
                   // tj += " AND OperationTime <= '" + Time_End + "'";
                }
                if (LogType != null && LogType != "")
                {
                    predicate = predicate.And(o => o.OperationType == LogType);
                    //tj += " AND OperationType LIKE '%" + LogType + "%'";
                }
                if (Operat_Result != null && Operat_Result != "")
                {
                    predicate = predicate.And(o => o.OperationRes == Operat_Result);
                   // tj += " AND OperationRes LIKE '%" + Operat_Result + "%'";
                }
                //string SQL = @"SELECT TOP " + pageSize + " * FROM  View_Order_OperationFlowInfo where OperationFlowID not in (SELECT TOP " + pageSize * (pageIndex - 1) + " OperationFlowID FROM View_Order_OperationFlowInfo where  1=1 " + tj + ") " + tj + " \n SELECT count(*) FROM  View_Order_OperationFlowInfo where  1=1 " + tj + "";
                List<Model.View_Order_OperationFlowInfo> list = new List<Model.View_Order_OperationFlowInfo>();
                //Help.ComdSqlFactory cmd = new Help.ComdSqlFactory();
                //DataSet ds = new DataSet();
                //if (cmd.ExecuteSelectCmmond(SQL, ds))
                //{
                //    list = Help.ParseClass<Model.View_Order_OperationFlowInfo>.ReturnList(ds.Tables[0]);
                //}
                //list = base.GetListBy(SQL);
                int tol = 0;

                list = base.GetPagedList<int>(pageIndex, pageSize, ref tol, predicate, u => u.OperationFlowID);
                if (list != null && list.Count > 0)// list不为空，表示有数据
                {
                    result.BS = "1";
                    result.Msg = "获取成功";
                    result.total = tol;
                    result.rows = list;
                }
                else// 否则表示没有数据
                {
                    result.BS = "0";
                    result.Msg = "没有数据";
                    result.total = 0;
                    result.rows = null;
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("获取系统操作流水列表失败：" + ex.Message);
                result.BS = "-1";
                result.Msg = "获取失败";
            }
            #endregion
            return os.StringOfObject(result, RETID);
        } 

    }
}
